<?php

	require_once('Table.php');
	require_once('SQL.php');

	abstract class Joob_Db_RelativeTable extends Joob_Db_Table
	{
		function __construct($db, $foreign_db, $foreign_class){
			parent::__construct($db);
            $this->foreign_db=$foreign_db;            
            $this->foreign_class=$foreign_class;            
		}
        
        
        
        /**
        * Function: setForeignKey()
        * -----------------------------------
        * 
        * @param mixed $foreign_key
        * @param mixed $foreign_key_db
        */
        
        public function setForeignKey($foreign_key, $foreign_key_value){            
            // $this->foreign_class=$foreign_class;
            $this->foreign_key=$foreign_key;
            $this->foreign_key_value=$foreign_key_value;
        }
        
        
        /**
        * Function: loadForeignKey()
        * -----------------------------------
        * Load the parent element using the foreign key.
        * @example  $comment=new BlogComment();
        *           $comment->setForeignKey('blog_id','1'); # Comment of blog with id=1
        *           $comment->loadForeignKey();
        * @param no params
        */
        public function loadForeignKey(){
            $class=$this->foreign_class;
            $elem=new $class();
            $elem->setOption('id',$this->foreign_key_value);
            if ($elem->connect()==false) return false;
            return $elem;
        }
        
        
        public function unique($field){
            
        }
        
        
        
        /**
        * Function: fwhere()
        * -----------------------------------
        * Check for foreign key/value pair.
        */
        protected function fwhere(){
              return " {$this->foreign_key}='{$this->foreign_key_value}' ";
        }
        
        
        # VARIABLE LISTS
        protected $foreign_db, $foreign_key, $foreign_class, $foreign_key_value;
	}
?>